package com.yy.permissions_general.module.system.schedule.controller;

import com.yy.permissions_general.common.aopSubmit.aop.NoRepeatSubmit;
import com.yy.permissions_general.module.system.aopLog.aop.MyLog;
import com.yy.permissions_general.module.system.schedule.entity.ScheduleLog;
import com.yy.permissions_general.module.system.schedule.service.ScheduleLogService;
import com.yy.permissions_general.utils.ResultUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;


/**
 * <p>
 * 定时任务日志前端控制器
 * </p>
 *
 * @author YY
 * @since 2022-02-09
 */
@RestController
@RequestMapping("/scheduleLog")
public class ScheduleLogController {

    @Resource
    private ScheduleLogService scheduleLogService;

    /**
    * 查询列表
    * @param scheduleLog
    * @param limit
    * @param page
    * @return
    */
    @MyLog("查询列表")
    @NoRepeatSubmit(key="scheduleLog.list")
    @RequestMapping("/list")
    public ResultUtil list(ScheduleLog scheduleLog, @RequestParam(value = "limit",defaultValue = "999999")int limit, @RequestParam(value = "page",defaultValue = "0")int page) {
      return ResultUtil.buildPagination(scheduleLogService.selectPageList(scheduleLog,limit,page));
    }

    /**
    * 根据ID删除记录
    * @param logId
    * @return
    */
    @MyLog("删除")
    @NoRepeatSubmit(key="scheduleLog.delete")
    @PreAuthorize("hasPermission('/scheduleLog/delete','scheduleLog:delete')")
    @RequestMapping("/delete")
    public ResultUtil delete(String logId) {
        scheduleLogService.deleteById(logId);
        return ResultUtil.success();
    }

    /**
    * 批量删除数据
    * @param ids ID集合
    * @return
    */
    @MyLog("批量删除")
    @NoRepeatSubmit(key="scheduleLog.deleteBatch")
    @PreAuthorize("hasPermission('/scheduleLog/deleteBatch','scheduleLog:deleteBatch')")
    @RequestMapping("/deleteBatch")
    public ResultUtil deleteBatch(@RequestParam(value = "ids[]",required = true) List<Long> ids) {
        scheduleLogService.deleteBatch(ids);
        return ResultUtil.success();
    }

}
